<template>
  <div id="AddScheduling">
    <el-form :model="schedulingData" label-width="200px">
      <el-form-item label="计划名称">
        <el-input v-model="schedulingData.schedulingName" clearable></el-input>
      </el-form-item>
      <el-form-item label="起始日期">
        <el-date-picker
          @change="handleDateChange"
          v-model="startEndData"
          type="datetimerange"
          align="right"
          unlink-panels
          value-format="yyyy-MM-dd HH:mm:ss"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          :picker-options="pickerOptions">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="参加团队">
        <el-select v-model="schedulingData.teamId" clearable>
          <el-option v-for="team in teamList" :key="team.id" :label="team.teamName" :value="team.id"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="primary" @click="saveScheduling">确定计划</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { listTeam } from '@/api/team'
import { insertScheduling } from '@/api/scheduling'

export default {
  name: 'AddScheduling',
  data() {
    return {
      pickerOptions: {},
      schedulingData: {
        schedulingName: '',
        teamId: '',
        startDateTime: '',
        endDateTime: ''
      },
      startEndData: [],
      schedulingRules: {},
      teamList: []
    }
  },
  mounted() {
    this.getTeamOptions()
  },
  methods: {
    getTeamOptions() {
      listTeam().then(res => {
        this.teamList = res.data.list
      })
    },
    handleDateChange(value) {
      this.schedulingData.startDateTime = value[0]
      this.schedulingData.endDateTime = value[1]
    },
    saveScheduling() {
      insertScheduling(this.schedulingData).then(res => {
        if (res.resultCode === 200) {
          this.$message.success('操作成功')
        }
      })
    }
  }
}
</script>

<style scoped>

</style>
